<%-- 
    Document   : search
    Created on : 28/09/2014, 05:12:10 PM
    Author     : Edwin, Cristian
--%>

<%@page import="com.hp.hpl.jena.util.FileManager"%>
<%@page import="java.io.InputStream"%>
<%@page import="Class.*" %>
<%@page import="javazoom.upload.*,java.util.*" %>

<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
</jsp:useBean>
<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8' /> 
        <link href='../css/style.css' rel='stylesheet' type='text/css' />
        <title>RDF Viewer</title>
    </head>
    <body>
    <center>
        <div id="result">
            <%-- Load File in folder Temp --%>
            <%
                String jspPath = session.getServletContext().getRealPath("/");
                String fullPath = jspPath + "\\uploads\\";
                upBean.setFolderstore(jspPath + "\\uploads");
                if (MultipartFormDataRequest.isMultipartFormData(request)) {
                    // Uses MultipartFormDataRequest to parse the HTTP request.
                    MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);

                    Hashtable files = mrequest.getFiles();
                    if ((files != null) && (!files.isEmpty())) {
                        UploadFile file = (UploadFile) files.get("urlSearch");
                        if (file != null) {
                            // Uses the bean now to store specified by jsp:setProperty at the top.
                            upBean.store(mrequest, "urlSearch");
                            fullPath += file.getFileName();
                        } else {%>
            <h1 class="error">
                <%
                    out.print("Error loading file.");
                    //out.println("<li>Form field : uploadfile" + "<BR> Uploaded file : " + file.getFileName() + " (" + file.getFileSize() + " bytes)" + "<BR> Content Type : " + file.getContentType());
                %>
            </h1> 
            <%}
            } else {%>
            <h1 class="error">
                <%
                    out.print("Error loading file.");
                %>
            </h1>
            <%}%>

            <%
                if (mrequest.getParameter("txtSearch") != null) {
                    Search s = new Search();
                    StringBuilder result = s.InitializeSearch(fullPath, mrequest.getParameter("txtSearch"));
                    if (result != null) {
                        String[] resultArray = result.toString().split("\n");
                        for (int i = 0; i < resultArray.length; i++) {
                            out.println(resultArray[i]);
            %><br /><%
                }
            } else {%>
            <h1 class="error">
                <%out.print("Not found similar data.");%>
            </h1>
            <%
                }
            } else {%>
            <h1 class="error">
                <%out.print("Has ocurred an Error.");%>
            </h1>
            <%}
                }
            %>
        </div>
    </center>
</body>
</html>
